#ifndef VEC2_H_
#define VEC2_H_

/************************************************************************/
/*  Vector class: Callum Brighting                                      */
/************************************************************************/
class Vec2
{
public:
    /* Default Ctr. */
	Vec2() 
	{
		m_x = 0;
		m_y = 0;
	}
    /* Overloaded Ctr. */
	Vec2( const float x, const float y) 
	{
		m_x = x;
		m_y = y;
	}
    //Access functions 
    float X() const
	{
		return m_x;
	}
	float Y() const
	{
		return m_y;
	}
	float& X()
	{
		return m_x;
	}
	float& Y()
	{
		return m_y;
	}
    /* Adds the given vector to this*/
	Vec2& operator+=(const Vec2& rhs)
	{
		m_x += rhs.m_x;
		m_y += rhs.m_y;
		return *this;
	}
    /* returns a vector of the given value added to this*/
    Vec2 operator+(const Vec2& rhs) const
    {
        return Vec2(m_x + rhs.X(), m_y + rhs.Y());
    }
    /* Minuses the given vector from this*/
	Vec2& operator-=(const Vec2& rhs)
	{
		m_x -= rhs.m_x;
		m_y -= rhs.m_y;
		return *this;
	}
    /* returns a vector of the given minused from this*/
    Vec2 operator-(const Vec2& rhs) const
    {
        return Vec2(m_x - rhs.X(), m_y - rhs.Y());
    }
    /* multiplies the vector by the given value*/
	Vec2& operator *= (const float f)
	{
		m_x *= f;
		m_y *= f;
		return *this;
	}
    /* returns a value of the given scalar muliplied by this*/
    Vec2 operator*(const float f) const
    {
        return Vec2(m_x * f, m_y * f);
    }
    /* Index operators returning by value or reference. 
    depending on const-ness */
    float operator[](unsigned i) const
    {
        if (i == 0) return m_x;
        return m_y;
    }

    float& operator[](unsigned i) 
    {
        if (i == 0) return m_x;
        return m_y;
    }

    Vec2 GetInverted() const
    {
        return Vec2(-m_x, -m_y);
    }

    void Set(float x, float y)
    {
        m_x = x; m_y = y;
    }
public:
	float m_x;
	float m_y;
};

#endif